﻿//
// Created by 17616 on 2021/5/14.
//
#include <vector>
#include <string>
#include <exception>
#include <iostream>
#include "public.h"
#include <opencv2/opencv.hpp>
#include <thread>


std::vector<int> CompressionPara = {
        cv::IMWRITE_PNG_COMPRESSION,
        9//参数越大，压缩比例越高
};


int m_main(const std::vector<std::string> &args) {
    if (args.size() != 2) {
        printf("请传入俩张图\r\n");
        system("pause");
        return 0;
    }
    printf("Hardware concurrency=%d\r\n", std::thread::hardware_concurrency());
    cv::Mat mat0 = cv::imread(args[0], cv::IMREAD_UNCHANGED);
    cv::Mat mat1 = cv::imread(args[1], cv::IMREAD_UNCHANGED);

    thread_pool tp(0, mat0.rows);

    if (mat0.size != mat1.size ||
        mat0.type() != mat1.type()) {
        printf("尺寸或者类型不一样\r\n");
        system("pause");
        return 0;
    }
    tp.post([&](int s, int e) {
        for (int r = s; r < e; ++r) {
            for (int c = 0; c < mat0.cols; ++c) {
                if (mat0.at<char>(r, c) != mat1.at<char>(r, c)) {
                    printf("在(%d,%d),二者不同(%x,%x)\r\n", r, c,
                           mat0.at<char>(r, c), mat1.at<char>(r, c));
                }
            }
        }
    });
    tp.join();

    printf("对比完成无异常");
    system("pause");
    return 0;
}

int main(int argn, const char **argv) {
    if (argn == 1) {
        printf("检查图片像素点是否匹配\r\n");
        std::system("pause");
        return 0;
    }
    std::vector<std::string> args;
    if (strcmp(argv[1], "--test") == 0) {
        args.push_back("C:\\Users\\17616\\Desktop\\Snipaste_2021-05-11_19-49-14.bmp");
    } else {
        for (int i = 1; i < argn; ++i) {
            args.emplace_back(argv[i]);
        }
    }
    return m_main(args);
}